import request from '@/utils/request'
import request1 from '@/utils/request1'

import qs from 'querystring'

export function login(data) {
  return request({
    url: '/connect/token',
    method: 'post',
    headers: {
      'content-type': 'application/x-www-form-urlencoded',
      'Accept-Language': 'zh-Hans,zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'
    },
    data: qs.stringify(data),
    baseURL: public_config.auth_api
  })
  // return new Promise((resolve, reject) => {
  //   const serv = axios.create({
  //     timeout: 5000 // request timeout
  //   })
  //   serv({
  //     url: process.env.auth_api + '/connect/token',
  //     headers: { 'content-type': 'application/x-www-form-urlencoded',
  //       'Accept-Language': 'zh-Hans,zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'
  //     },
  //     method: 'post',
  //     data: qs.stringify(data)
  //   }).then(res => {
  //     console.log('执行了一次token请求')
  //     if (res.status === 200) {
  //       commit('SET_TOKEN', res.data.access_token)
  //       setToken(res.data.access_token)
  //       resolve(res.data.access_token)
  //     } else {
  //       reject('Error')
  //     }
  //   }, err => {
  //     reject(err)
  //   })
  // }
}

export function getInfo() {
  return request({
    url: '/api/account/my-profile',
    method: 'get',
    baseURL: public_config.configuration_api
  })
}

export function getUserDetails(params) {
  return request({
    url: '/api/app/employee/employee',
    method: 'get',
    baseURL: public_config.control_api,
    params
  })
}

export function logout() {
  // return request({
  //   // url: '/vue-element-admin/user/logout',
  //   url: '/user/logout',
  //   method: 'post'
  // })
  return request({
    url: '/api/account/logout',
    method: 'get',
    baseURL: public_config.auth_api
  })
}

export function sendResetPwdCode(data) {
  return request({
    url: '/Identity/reset-pwd-send-phone-code',
    method: 'post',
    data,
    baseURL: public_config.auth_api
  })
}

export function resetPwd(data) {
  return request({
    url: '/Identity/reset-pwd',
    method: 'post',
    data,
    baseURL: public_config.auth_api
  })
}

export function loginSuccess() {
  return request({
    url: `/api/app/user/loginSucceeded`,
    method: 'post',
    baseURL: public_config.VUE_CRM_APP_BASE_API
  })
}

export function changePassword(data) {
  return request({
    url: "/api/account/my-profile/change-password",
    method: "post",
    data,
    baseURL: public_config.configuration_api
  });
}

export function isLoginBefore(data) {
  return request({
    url:'/api/app/identity/isLoginBefore',
    method: 'post',
    data,
    baseURL:public_config.control_api
  })
}
/*
融合start
*/ 
// 账号登录
export function submitLogin(workNumber, password, code, uuid){
  const data = {
    workNumber,
    password,
    code,
    uuid
  }
  return request1({
    url:'/login',
    method: 'post',
    data,
  
  })
}
export function smsLogin(data){
  return request1({
    url:'/smsLogin',
    method: 'post',
    data,
  
  })
}
// 获取用户详细信息
export function getUserInfo() {
  return request1({
    url: '/getInfo',
    method: 'get',

  })
}

// /getCode 获取验证码
export function getCode(params) {
  return request1({
    url: '/getCode',
    method: 'get',
    params,

  })
}
//根据手机号获取用户信息
export function getUserByPhone(params) {
  return request1({
    url: '/getUserByPhone',
    method: 'get',
    params,
  
  })
}
// //登录页面修改密码=》根据手机及验证码获取用户信息
export function sendCodeForResetPwd(params) {
  return request1({
    url: '/sendCodeForResetPwd',
    method: 'get',
    params,
 
  })
}
// 登录页面修改密码
// /resetPwd
export function resetUserPwd(data){
  return request1({
    url: '/resetPwd',
    method: 'put',
    data,
   

  })
}
// 获取路由
export function getRouters () {
  return request1({
    url: '/getRouters',
    method: 'get'
  })
}
/*
融合end
*/ 

export function setIsLogin(data) {
  return request({
    url:'/api/app/identity/setIsLogin',
    method: 'post',
    data,
    baseURL:public_config.control_api
  })
}